﻿using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using RxjhServer.DbClss;

namespace RxjhServer
{
	public partial class Form2 : Form
	{
		public Form2()
		{
			this.InitializeComponent();
		}

		public static void FlushAll1()
		{
			int num = 0;
			Form1.WriteLine(100, "删除人物数据开始");
			string sqlCommand = string.Format("select * from TBL_人物数据", new object[0]);
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand);
			if (dBToDataTable != null)
			{
				Form1.WriteLine(100, "共有人物数据" + dBToDataTable.Rows.Count);
				for (int i = 0; i < dBToDataTable.Rows.Count; i++)
				{
					string sqlCommand2 = string.Format("select count(*) from TBL_ACCOUNT where FLD_ID='{0}'", dBToDataTable.Rows[i]["FLD_ID"]);
					int num2 = (int)DBA.GetDBValue_3(sqlCommand2, "rxjhaccount");
					if (num2 < 1)
					{
						num++;
						Form1.WriteLine(100, string.Concat(new object[]
						{
							"删除人物[",
							dBToDataTable.Rows[i]["FLD_ID"].ToString(),
							"] [",
							dBToDataTable.Rows[i]["FLD_NAME"],
							"]"
						}));
						sqlCommand = string.Format("DELETE FROM TBL_人物数据 WHERE FLD_NAME  ='{0}'", dBToDataTable.Rows[i]["FLD_NAME"].ToString());
						DBA.ExeSqlCommand(sqlCommand);
						sqlCommand = string.Format("DELETE FROM TBL_个人仓库 WHERE FLD_NAME  ='{0}'", dBToDataTable.Rows[i]["FLD_NAME"].ToString());
						DBA.ExeSqlCommand(sqlCommand);
						string sqlCommand3 = string.Format("select * from TBL_帮派成员 WHERE Name ='{0}'", dBToDataTable.Rows[i]["FLD_NAME"].ToString());
						DataTable dBToDataTable2 = DBA.GetDBToDataTable(sqlCommand3);
						if (dBToDataTable2 != null)
						{
							if (dBToDataTable2.Rows.Count > 0)
							{
								if (dBToDataTable2.Rows[0]["leve"].ToString() == "6")
								{
									Form1.WriteLine(100, "删除帮派" + dBToDataTable2.Rows[0]["G_Name"]);
									sqlCommand = string.Format("DELETE FROM TBL_帮派数据 WHERE G_Name  ='{0}'", dBToDataTable2.Rows[0]["G_Name"].ToString());
									DBA.ExeSqlCommand(sqlCommand);
									sqlCommand = string.Format("DELETE FROM TBL_帮派成员 WHERE G_Name  ='{0}'", dBToDataTable2.Rows[0]["G_Name"].ToString());
									DBA.ExeSqlCommand(sqlCommand);
								}
								else
								{
									sqlCommand = string.Format("DELETE FROM TBL_帮派成员 WHERE Name  ='{0}'", dBToDataTable.Rows[i]["FLD_NAME"].ToString());
									DBA.ExeSqlCommand(sqlCommand);
								}
							}
							dBToDataTable2.Dispose();
						}
					}
				}
				dBToDataTable.Dispose();
			}
			Form1.WriteLine(100, "删除人物数据完成" + num);
		}

		public static void FlushAll2()
		{
			int num = 0;
			Form1.WriteLine(100, "删除人物仓库数据开始");
			string sqlCommand = string.Format("select * from TBL_个人仓库", new object[0]);
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand);
			if (dBToDataTable != null)
			{
				Form1.WriteLine(100, "共有人物数据" + dBToDataTable.Rows.Count);
				for (int i = 0; i < dBToDataTable.Rows.Count; i++)
				{
					string sqlCommand2 = string.Format("select * from TBL_人物数据 where FLD_NAME='{0}'", dBToDataTable.Rows[i]["FLD_NAME"]);
					DataTable dBToDataTable2 = DBA.GetDBToDataTable(sqlCommand2);
					if (dBToDataTable2.Rows.Count < 1)
					{
						num++;
						Form1.WriteLine(100, string.Concat(new object[]
						{
							"删除人物仓库[",
							dBToDataTable.Rows[i]["FLD_ID"].ToString(),
							"] [",
							dBToDataTable.Rows[i]["FLD_NAME"],
							"]"
						}));
						sqlCommand = string.Format("DELETE FROM TBL_个人仓库 WHERE FLD_ID='{0}'and FLD_NAME  ='{1}'", dBToDataTable.Rows[i]["FLD_ID"].ToString(), dBToDataTable.Rows[i]["FLD_NAME"].ToString());
						DBA.ExeSqlCommand(sqlCommand);
					}
					else if (dBToDataTable2.Rows[0]["FLD_ID"].ToString() != dBToDataTable.Rows[i]["FLD_ID"].ToString())
					{
						num++;
						Form1.WriteLine(100, string.Concat(new object[]
						{
							"删除人物仓库[",
							dBToDataTable.Rows[i]["FLD_ID"].ToString(),
							"] [",
							dBToDataTable.Rows[i]["FLD_NAME"],
							"]"
						}));
						sqlCommand = string.Format("DELETE FROM TBL_个人仓库 WHERE FLD_ID='{0}'and FLD_NAME  ='{1}'", dBToDataTable.Rows[i]["FLD_ID"].ToString(), dBToDataTable.Rows[i]["FLD_NAME"].ToString());
						DBA.ExeSqlCommand(sqlCommand);
					}
					dBToDataTable2.Dispose();
				}
				dBToDataTable.Dispose();
			}
			Form1.WriteLine(100, "删除人物仓库数据完成" + num);
		}

		public static void FlushAll3()
		{
			int num = 0;
			Form1.WriteLine(100, "删除宗合仓库开始");
			string sqlCommand = string.Format("select * from TBL_综合仓库", new object[0]);
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand);
			if (dBToDataTable != null)
			{
				Form1.WriteLine(100, "共有宗合仓库数据" + dBToDataTable.Rows.Count);
				for (int i = 0; i < dBToDataTable.Rows.Count; i++)
				{
					string sqlCommand2 = string.Format("select count(*) from TBL_ACCOUNT where FLD_ID='{0}'", dBToDataTable.Rows[i]["FLD_ID"]);
					int num2 = (int)DBA.GetDBValue_3(sqlCommand2, "rxjhaccount");
					if (num2 < 1)
					{
						num++;
						Form1.WriteLine(100, "删除宗合仓库[" + dBToDataTable.Rows[i]["FLD_ID"].ToString() + "]");
						sqlCommand = string.Format("DELETE FROM TBL_综合仓库 WHERE FLD_ID  ='{0}'", dBToDataTable.Rows[i]["FLD_ID"].ToString());
						DBA.ExeSqlCommand(sqlCommand);
					}
				}
				dBToDataTable.Dispose();
			}
			Form1.WriteLine(100, "删除宗合仓库完成" + num);
		}

		public static void FlushAll4()
		{
			int num = 0;
			Form1.WriteLine(100, "删除帮派数据开始");
			string sqlCommand = string.Format("select * from TBL_帮派数据", new object[0]);
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand);
			if (dBToDataTable != null)
			{
				Form1.WriteLine(100, "共有人物数据" + dBToDataTable.Rows.Count);
				for (int i = 0; i < dBToDataTable.Rows.Count; i++)
				{
					string sqlCommand2 = string.Format("select * from TBL_人物数据 where FLD_NAME='{0}'", dBToDataTable.Rows[i]["G_Master"]);
					DataTable dBToDataTable2 = DBA.GetDBToDataTable(sqlCommand2);
					if (dBToDataTable2.Rows.Count < 1)
					{
						num++;
						Form1.WriteLine(100, string.Concat(new object[]
						{
							"删除帮派[",
							dBToDataTable.Rows[i]["G_Name"].ToString(),
							"] [",
							dBToDataTable.Rows[i]["G_Master"],
							"]"
						}));
						sqlCommand = string.Format("DELETE FROM TBL_帮派数据 WHERE G_Name  ='{0}'", dBToDataTable.Rows[i]["G_Name"].ToString());
						DBA.ExeSqlCommand(sqlCommand);
						sqlCommand = string.Format("DELETE FROM TBL_帮派成员 WHERE G_Name  ='{0}'", dBToDataTable.Rows[i]["G_Name"].ToString());
						DBA.ExeSqlCommand(sqlCommand);
					}
					dBToDataTable2.Dispose();
				}
				dBToDataTable.Dispose();
			}
			Form1.WriteLine(100, "删除帮派数据完成" + num);
			Form2.FlushAll5();
		}

		public static void FlushAll5()
		{
			int num = 0;
			Form1.WriteLine(100, "删除帮派数据开始");
			string sqlCommand = string.Format("select * from TBL_帮派成员", new object[0]);
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand);
			if (dBToDataTable != null)
			{
				Form1.WriteLine(100, "共有帮派数据" + dBToDataTable.Rows.Count);
				for (int i = 0; i < dBToDataTable.Rows.Count; i++)
				{
					string sqlCommand2 = string.Format("select * from TBL_人物数据 where FLD_NAME='{0}'", dBToDataTable.Rows[i]["Name"]);
					DataTable dBToDataTable2 = DBA.GetDBToDataTable(sqlCommand2);
					if (dBToDataTable2.Rows.Count < 1)
					{
						num++;
						if (dBToDataTable.Rows[0]["leve"].ToString() == "6")
						{
							Form1.WriteLine(100, "删除帮派" + dBToDataTable.Rows[i]["G_Name"]);
							sqlCommand = string.Format("DELETE FROM TBL_帮派数据 WHERE G_Name  ='{0}'", dBToDataTable.Rows[0]["G_Name"].ToString());
							DBA.ExeSqlCommand(sqlCommand);
							sqlCommand = string.Format("DELETE FROM TBL_帮派成员 WHERE G_Name  ='{0}'", dBToDataTable.Rows[0]["G_Name"].ToString());
							DBA.ExeSqlCommand(sqlCommand);
						}
						else
						{
							Form1.WriteLine(100, string.Concat(new object[]
							{
								"删除帮派",
								dBToDataTable.Rows[i]["G_Name"],
								"    ",
								dBToDataTable.Rows[i]["Name"].ToString()
							}));
							sqlCommand = string.Format("DELETE FROM TBL_帮派成员 WHERE Name  ='{0}'", dBToDataTable.Rows[i]["Name"].ToString());
							DBA.ExeSqlCommand(sqlCommand);
						}
					}
					dBToDataTable2.Dispose();
				}
				dBToDataTable.Dispose();
			}
			Form1.WriteLine(100, "删除帮派数据完成" + num);
		}

		private void Form2_Load(object sender, EventArgs e)
		{
			this.listView2.ListViewItemSorter = new ListViewColumnSorter();
			this.listView2.ColumnClick += new ColumnClickEventHandler(ListViewHelper.ListView_ColumnClick);
			foreach (地面物品类 current in World.ItmeTeM.Values)
			{
				try
				{
					string[] array = new string[17];
					try
					{
						array[0] = BitConverter.ToInt64(current.物品.物品全局ID, 0).ToString();
						array[1] = BitConverter.ToInt32(current.物品.物品ID, 0).ToString();
						array[2] = current.物品.得到物品名称();
						array[3] = current.Rxjh_Map.ToString();
						array[4] = current.Rxjh_X.ToString();
						array[5] = current.Rxjh_Y.ToString();
						array[6] = current.物品.FLD_MAGIC0.ToString();
						array[7] = current.物品.FLD_MAGIC1.ToString();
						array[8] = current.物品.FLD_MAGIC2.ToString();
						array[9] = current.物品.FLD_MAGIC3.ToString();
						array[10] = current.物品.FLD_MAGIC4.ToString();
						array[11] = current.物品优先权.UserName;
					}
					catch
					{
						array[0] = BitConverter.ToInt64(current.物品.物品全局ID, 0).ToString();
						array[1] = BitConverter.ToInt32(current.物品.物品ID, 0).ToString();
						array[2] = current.物品.得到物品名称();
						array[3] = current.Rxjh_Map.ToString();
						array[4] = current.Rxjh_X.ToString();
						array[5] = current.Rxjh_Y.ToString();
						array[6] = current.物品.FLD_MAGIC0.ToString();
						array[7] = current.物品.FLD_MAGIC1.ToString();
						array[8] = current.物品.FLD_MAGIC2.ToString();
						array[9] = current.物品.FLD_MAGIC3.ToString();
						array[10] = current.物品.FLD_MAGIC4.ToString();
					}
					this.listView2.Items.Insert(this.listView2.Items.Count, new ListViewItem(array));
				}
				catch
				{
				}
			}
		}
	}
}
